<?php
require_once '../../bbs/include/common.inc.php';
require_once '../../classes/include.php';


if(!empty($_POST['add']))
{
	$uploaddir = "../../attachment_files/";//设置文件保存目录 注意包含/
	
		$filename = explode(".",$_FILES['file']['name']);
		do
		{
			$filename[0] = md5(time()); 
			$video_name = implode(".",$filename);
			//$uploadfile = $uploaddir.$sort.'/'.$video_name;
			$uploadfile = $uploaddir.'/'.$video_name;
		}
		while(file_exists($uploadfile));
		
		if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile))
		{
			$sql = "insert into js_attachment (attachment_name ) values
					('".$video_name."')";

			$query = $db->query($sql);
			
			echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />";
			echo "<script>";
			echo "alert('增加成功!');";
			echo "location.href='list.php';";
			echo "</script>";
			exit;			
		}
		else
		{
			echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />";
			echo "<script>";
			echo "alert('上传失败!');";
			echo "location.href='list.php';";
			echo "</script>";
			exit;
		}
	//}
}
?>

<html><head>
<title></title>
<meta name="robots" content="noindex, nofollow" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="../ckeditor.js"></script>
<script type="text/javascript" src="../../js/jquery.js"></script>
<link rel="stylesheet" href="../../bbs/images/admincp/admincp.css" type="text/css" media="all" /> 
<script type="text/javascript">
<!--
function ChangeLanguage( languageCode )
{
	window.location.href = window.location.pathname + "?" + languageCode ;
}

function Check(frm)
{
	return true;
}
//-->
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<form enctype="multipart/form-data" action="add.php" method="post" onsubmit="return Check(this)">
  <table cellspacing=1 cellpadding=3 width="100%" align=center bgcolor="#CBDFF3" border=0>
    <tr class="tableheader"> 
      <td colspan="2">&nbsp;&nbsp;增加附件</td>
    </tr>
	<tr class="tablecontent"> 
		<td align="left">&nbsp;&nbsp;选择文件:</td>
		<td>
    		<input name='file' type='file'>
    	</td>
    </tr>
  </table>
  <BR>
  <div id='wait'></div>
  <BR>
  <table cellspacing=1 cellpadding=3 width="95%" align=center bgcolor="#FFFFFF" border=0>
    <tr> 
      <td colspan="2" align="center"> 
        <input type="submit" id="add_button" name="add" value="增加">
        <input type="button" value="返回" onclick="javascript:location.href='./list.php';">
      </td>
    </tr>
  </table>
</form>
</body>
</html>